package com.yellowpage.bigdata.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.bigdata.data.TmApponoffContinuousActiveWeek;
import com.yellowpage.bigdata.dao.TmApponoffContinuousActiveWeekDao;

public class TmApponoffContinuousActiveWeekServiceImpl extends BaseServiceImpl
		implements TmApponoffContinuousActiveWeekService {
	private TmApponoffContinuousActiveWeekDao tmApponoffContinuousActiveWeekDao;

	public void setTmApponoffContinuousActiveWeekDao(
			TmApponoffContinuousActiveWeekDao tmApponoffContinuousActiveWeekDao) {
		this.tmApponoffContinuousActiveWeekDao = tmApponoffContinuousActiveWeekDao;
	}

	/* Smooth generate Method */
	public TmApponoffContinuousActiveWeek getTmApponoffContinuousActiveWeek(
			Long id) {
		return tmApponoffContinuousActiveWeekDao.get(id);
	}

	public List<TmApponoffContinuousActiveWeek> getAllTmApponoffContinuousActiveWeek() {
		return tmApponoffContinuousActiveWeekDao.getAll();
	}

	public List<Map> queryTmApponoffContinuousActiveWeekByPage(Map queryMap,
			PageRender pageRender) {

		QueryAssistantSQL sqlAssistant = baseDao
				.newQueryAssistantSQL(
						"SELECT a.WEEK_DATE ,  a.NEW_USER , a.BACK_USER , a.TWO_WEEK , a.THREE_WEEK , a.FOUR_WEEK , a.FIVE_WEEK , b.CNTS FROM "
								+ "TM_APPONOFF_CONTINUOUS_ACTIVE_WEEK_DEAIL a INNER JOIN TM_APPONOFF_ACTIVE_WEEK b ON a.WEEK_DATE = b.DAY_ID "
								+ "AND b.CHANNEL_NO = 'A'AND b.VERSION = 'A' GROUP BY a.WEEK_DATE")
				.addCondition(" AND a.WEEK_DATE >= :weekDate ")
				.addCondition(" AND a.WEEK_DATE <= :weekDateEnd ");

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}

	public void saveTmApponoffContinuousActiveWeek(
			TmApponoffContinuousActiveWeek tmApponoffContinuousActiveWeek) {
		tmApponoffContinuousActiveWeekDao.save(tmApponoffContinuousActiveWeek);
	}

	public void updateTmApponoffContinuousActiveWeek(
			TmApponoffContinuousActiveWeek tmApponoffContinuousActiveWeek) {
		tmApponoffContinuousActiveWeekDao
				.update(tmApponoffContinuousActiveWeek);
	}

	public void delete(List deleteList) {
		tmApponoffContinuousActiveWeekDao.remove(deleteList);
	}

}